package com.xlhj.dynamic.common;

import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author: caijliu
 * @description: 统一返回结果类
 * @data: 06/08/2021 12:36
 */
@Data
@NoArgsConstructor
public class ResultData {

    /**
     * 是否成功
     */
    private Boolean success;

    /**
     * 返回码
     */
    private Integer code;

    /**
     * 返回信息
     */
    private String message;

    /**
     * 返回对象
     */
    private Object object;

    /**
     * 返回成功静态方法
     * @return
     */
    public static ResultData success() {
        ResultData resultData = new ResultData();
        resultData.setSuccess(true);
        resultData.setCode(ResultEnum.SUCCESS.getCode());
        resultData.setMessage(ResultEnum.SUCCESS.getMessage());
        return resultData;
    }

    /**
     * 返回失败静态方法
     * @return
     */
    public static ResultData fail() {
        ResultData resultData = new ResultData();
        resultData.setSuccess(false);
        resultData.setCode(ResultEnum.FAIL.getCode());
        resultData.setMessage(ResultEnum.FAIL.getMessage());
        return resultData;
    }

    public ResultData success(Boolean success) {
        this.setSuccess(success);
        return this;
    }

    public ResultData code(Integer code) {
        this.setCode(code);
        return this;
    }

    public ResultData message(String message) {
        this.setMessage(message);
        return this;
    }

    public ResultData object(Object object) {
        this.setObject(object);
        return this;
    }
}
